import {RPage} from "@/api/Objects";
import {PojBaseData, PojDao, PojVo} from "@/api/Objects/PojTypes.ts";

class PojApi {
    /**
     * 分页获取项目信息
     */
    public pagePojInfo = async (): Promise<RPage<PojBaseData>> => {
        // const data = await REQ<null, Res<Page<PojBaseData>>>({
        //     method: 'get',
        //     url: '/api/poj/pojInfo/basic/page',
        //     params: {
        //         current: 1,
        //         size: 10
        //     }
        // })
        // return data.data

        const res =  {
            "records": [],
            "total": 10,
            "size": 10,
            "current": 1,
            "pages": 1
        }

        for (let i = 0; i < 10; i++) {
            res.records.push(
                {
                    "id": (10010 + i).toString(),
                    "name": "测试项目",
                    "description": null,
                    "coverLink": "https://tu.ltyuanfang.cn/api/fengjing.php",
                    "heat": 100,
                    "creatorName": "测试用户",
                    "creatorAvatar": "https://pic2.zhimg.com/80/v2-0944a627d17db091fe5b1ea47f3c71dd_720w.webp"
                })
        }

        return res
    }

    public savePoj = async (data: PojVo) => {
        const date = new Date()
        const dateStr = date.toISOString();
        const _data: PojDao = {
            createTime: dateStr,
            updateTime: dateStr,
            ...data
        }

        const pojKey = 'pojDao'
        const pojList = localStorage.getItem(pojKey)
        let pl = null
        if (pojList == null) {
            pl = {
                pojList: []
            }
        }
        pl = JSON.parse(pojList)
        pl.pojList.add(_data)
        localStorage.setItem(pojKey, pl)
    }
}

export default new PojApi()